



//% color="#AA278D" iconWidth=50 iconHeight=40
namespace json {
    

     //% block="Post the ClientId[ClientId] Identifier[STR] value[Value]" blockType="reporter"
    //% STR.shadow="string" STR.defl=标识符
    //% ClientId.shadow="string" ClientId.defl=s12345
    //% Value.shadow="number"  Value.defl=1
    export function PostIdentifier(parameter: any, block: any) {
        let str = parameter.STR.code
        let val = parameter.Value.code
        let ClientId = parameter.ClientId.code
        Generator.addInclude('json', '#include <ArduinoJson.h>');
        Generator.addObject(`ClientId`, `String`, `ClientId;`);
        Generator.addObject(`Identifier`, `String`, `Identifier;`);
       
        Generator.addSetup(`ClientId`, `ClientId = ${ClientId};`);
        Generator.addSetup(`Identifier`, `Identifier = ${str};`);
       

        Generator.addCode(`("{\\"id\\":\\""+ClientId+"\\",\\"params\\":{\\""+Identifier+"\\":"+${val}+"},\\"method\\":\\"thing.event.property.post\\"}").c_str()`);
       
    }

    

    //% block="get the json[STR] params[params]" blockType="reporter"
    //% STR.shadow="string" STR.defl="MQTT消息"
    export function getjson(parameter: any, block: any) {
        let str = parameter.STR.code
        let params_val = parameter.params.code
        Generator.addInclude('json', '#include <ArduinoJson.h>');
        Generator.addObject(`jsonBuffer`, `DynamicJsonBuffer`, `jsonBuffer;`);
        Generator.addCode(`jsonBuffer.parseObject(${str})["params"][${params_val}]`);
    }

}
